package com.ksyun.campus.dataserver.exception;

import com.ksyun.campus.dataserver.response.BaseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(FileAlreadyExistsException.class)
    public BaseResult<Void> handleFileAlreadyExistsException(FileAlreadyExistsException ex) {
        return BaseResult.error(ex.getMessage());
    }

    @ExceptionHandler(FileNotFoundException.class)
    public BaseResult<Void> handleFileNotFoundException(FileNotFoundException ex) {
        return BaseResult.error(ex.getMessage());
    }

    @ExceptionHandler(OperationFailedException.class)
    public BaseResult<Void> handleOperationFailedException(OperationFailedException ex) {
        return BaseResult.error(ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public BaseResult<Void> handleGenericException(Exception ex) {
        return BaseResult.error("服务器内部错误: " + ex.getMessage());
    }
}
